package com.lianzhihui.romeex.ui.orepool;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.lianzhihui.romeex.MyApplication;
import com.lianzhihui.romeex.R;
import com.lianzhihui.romeex.adapter.EarningsActivityAdapter;
import com.lianzhihui.romeex.bean.SunTeamAwardBean;
import com.lianzhihui.romeex.mvp.presenter.EarningsPresnterImp;
import com.lianzhihui.romeex.mvp.view.EarningsView;
import com.lianzhihui.romeex.ui.base.BaseActivity;
import com.lianzhihui.romeex.utils.StatusBarUtil;
import com.lianzhihui.romeex.widget.ZFEmptyRecyclerView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.text.MessageFormat;
import java.util.ArrayList;

import butterknife.BindView;

/**
 * @ProjectName: romeex
 * @Package: com.lianzhihui.romeex.ui.orepool
 * @ClassName: MyTeamActivity
 * @Description: 收益明细
 * @Author: zhanghong
 * @CreateDate: 2020/11/24 15:02
 * @UpdateUser: 更新者：
 * @UpdateDate: 2020/11/24 15:02
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class EarningsActivity extends BaseActivity implements OnRefreshLoadMoreListener, EarningsView {
    @BindView(R.id.myRecyclerView)
    ZFEmptyRecyclerView myRecyclerView;

    @BindView(R.id.include_top_lin_background)
    LinearLayout includeTopLinBackground;
    @BindView(R.id.include_top_tv_title)
    TextView includeTopTvTitle;
    @BindView(R.id.status_bar_id)
    View statusBarId;
    @BindView(R.id.count)
    TextView count;
    @BindView(R.id.tv_community_num)
    TextView tvCommunityNum;
    @BindView(R.id.tv_fission_num)
    TextView tvFissionNum;
    @BindView(R.id.mySmartRefreshLayout)
    SmartRefreshLayout mySmartRefreshLayout;
    private EarningsActivityAdapter myTeamActivityAdapter;
    @BindView(R.id.include_top_iv_back)
    ImageView includeTopIvBack;
    private EarningsPresnterImp earningsPresnterImp;
    private final int pageSize = 20;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_earnings;

    }

    @Override
    public boolean setFitSystemWindowFlag() {
        return false;
    }

    @Override
    protected void initView() {
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarId.getHeight());
        layoutParams.topMargin = StatusBarUtil.getStatusBarHeight(MyApplication.mContext);
        statusBarId.setLayoutParams(layoutParams);
        includeTopTvTitle.setText(getResources().getText(R.string.text_my_team));
        StatusBarUtil.setStatusBarTextColor(this, false);
        StatusBarUtil.setTransparentForImageView(this, null);
        includeTopLinBackground.setBackgroundColor(getResources().getColor(R.color.trade_bg_F4F5F7_color));
        mySmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        earningsPresnterImp = new EarningsPresnterImp(this, this);
        mySmartRefreshLayout.autoRefresh();
    }

    @Override
    protected void initData() {
        myRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        myTeamActivityAdapter = new EarningsActivityAdapter(this, new ArrayList<>());
        myRecyclerView.setAdapter(myTeamActivityAdapter);
    }


    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        earningsPresnterImp.requestSunTeamAward(pageNum, pageSize);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        pageNum = 1;
        earningsPresnterImp.requestSunTeamAward(pageNum, pageSize);
    }


    @Override
    public void setFailure() {
        mySmartRefreshLayout.finishRefresh();
        mySmartRefreshLayout.finishLoadMore();
    }

    @Override
    public void responseSunTeamAwardSuccess(SunTeamAwardBean bean) {
        if (bean != null) {
            count.setText(MessageFormat.format("{0}{1}", bean.getTotalTeamBalance(), getString(R.string.text_rex)));
            tvCommunityNum.setText(MessageFormat.format("{0}{1}", bean.getTotalCommunityBalance(), getString(R.string.text_rex)));
            tvFissionNum.setText(MessageFormat.format("{0}{1}", bean.getTotalFissionBalance(), getString(R.string.text_rex)));
            if (bean.getContent() != null) {
                if (pageNum == 1) {
                    myRecyclerView.showEmptyView(bean.getContent().size(), pageNum);
                    myTeamActivityAdapter.setNewData(bean.getContent());
                } else {
                    myTeamActivityAdapter.addData(bean.getContent());
                }
            }
        }
        mySmartRefreshLayout.finishRefresh();
        mySmartRefreshLayout.finishLoadMore();
    }
}
